package com.guoyw.dubbo.example;

import com.guoyw.dubbo.example.serviceImpl.UserServiceImpl;
import com.guoyw.dubbo.member.service.UserService;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;

import java.io.IOException;

/**
 * author: guoyw
 * create: 2020-09-11 16:56
 **/

public class DubboServer{
  
  public static void main(String[] args) throws IOException{
    // 开始 暴露 UserService 服务
    // application
    // protocol -dubbo 协议
    // register
    // service
  
    ApplicationConfig applicationConfig = new ApplicationConfig("sample-app");
    ProtocolConfig protocolConfig = new ProtocolConfig();
    protocolConfig.setName("dubbo");
//    protocolConfig.setSerialization("fastjson");
    protocolConfig.setPort(20881);//20880
  
    RegistryConfig registryConfig = new RegistryConfig(RegistryConfig.NO_AVAILABLE);
    // RegistryConfig registryConfig = new RegistryConfig("zookeeper://192.168.0.147:2181");
  
    ServiceConfig serviceConfig = new ServiceConfig();
    serviceConfig.setInterface(UserService.class);
    serviceConfig.setRef(new UserServiceImpl());
    
    serviceConfig.setRegistry(registryConfig);
    serviceConfig.setProtocol(protocolConfig);
    serviceConfig.setApplication(applicationConfig);
    serviceConfig.export();
  
    System.out.println("服务已暴露");
    System.in.read();
  }
}
